﻿Imports System.Data.SqlClient

Public Class clsNominaGeneral
    Private mintIdNomina As Integer
    Private mintFolio As Integer
    Private mintInfonavit As Integer
    Private mintFonacot As Integer
    Private mintAnio As Integer
    Private mintNomina As Integer
    Private mintColumnas As Integer
    Private mdatFechaInicial As Date
    Private mdatFechaFinal As Date
    Private mdatFechaAplicacion As Date
    Public Property IdNomina() As Integer
        Get
            Return mintIdNomina
        End Get
        Set(ByVal value As Integer)
            mintIdNomina = value
        End Set
    End Property
    Public Property Folio() As Integer
        Get
            Return mintFolio
        End Get
        Set(ByVal value As Integer)
            mintFolio = value
        End Set
    End Property
    Public Property Infonavit() As Integer
        Get
            Return mintInfonavit
        End Get
        Set(ByVal value As Integer)
            mintInfonavit = value
        End Set
    End Property
    Public Property Fonacot() As Integer
        Get
            Return mintFonacot
        End Get
        Set(ByVal value As Integer)
            mintFonacot = value
        End Set
    End Property
    Public Property Anio() As Integer
        Get
            Return mintAnio
        End Get
        Set(ByVal value As Integer)
            mintAnio = value
        End Set
    End Property
    Public Property Nomina() As Integer
        Get
            Return mintNomina
        End Get
        Set(ByVal value As Integer)
            mintNomina = value
        End Set
    End Property
    Public Property Columnas() As Integer
        Get
            Return mintColumnas
        End Get
        Set(ByVal value As Integer)
            mintColumnas = value
        End Set
    End Property
    Public Property FechaInicial As Date
        Get
            Return mdatFechaInicial
        End Get
        Set(value As Date)
            mdatFechaInicial = value
        End Set
    End Property
    Public Property FechaFinal As Date
        Get
            Return mdatFechaFinal
        End Get
        Set(value As Date)
            mdatFechaFinal = value
        End Set
    End Property
    Public Property FechaAplicacion As Date
        Get
            Return mdatFechaAplicacion
        End Get
        Set(value As Date)
            mdatFechaAplicacion = value
        End Set
    End Property

    Public Sub New()
        mintIdNomina = 0
        mintFolio = 0
        mintInfonavit = 0
        mintFonacot = 0
        mintAnio = 0
        mintNomina = 0
        mintColumnas = 0
        mdatFechaInicial = Now()
        mdatFechaFinal = Now()
        mdatFechaAplicacion = Now()
    End Sub
    Public Sub Borrar()
        Call SetSqlCitra("Delete From NominaGeneral Where IdNomina = " & IdNomina)
    End Sub
    Public Sub Buscar()
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From NominaGeneral " & _
        " WHERE IDNOMINA=" & IdNomina

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then

            mintFolio = rdBuscar("folio")
            mintInfonavit = rdBuscar("infonavit")
            mintFonacot = rdBuscar("fonacot")
            mintAnio = rdBuscar("anio")
            mintNomina = rdBuscar("nomina")
            mintColumnas = rdBuscar("columnas")
            mdatFechaInicial = rdBuscar("fechainicial")
            mdatFechaFinal = rdBuscar("fechafinal")
            mdatFechaAplicacion = rdBuscar("fechaaplicacion")
        Else
            mintIdNomina = 0
            mintFolio = 0
            mintInfonavit = 0
            mintFonacot = 0
            mintAnio = 0
            mintNomina = 0
            mintColumnas = 0
            mdatFechaInicial = Now()
            mdatFechaFinal = Now()
            mdatFechaAplicacion = Now()
        End If

        rdBuscar.Close()
        cnConn.Close()


    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into NominaGeneral (" & _
                            "Folio," & _
                            "Infonavit," & _
                            "Fonacot," & _
                            "Anio," & _
                            "Nomina," & _
                            "Columnas," & _
                            "FechaInicial," & _
                            "FechaFinal," & _
                            "FechaAplicacion)" & _
                            "VALUES (" & _
                            "@Folio," & _
                            "@Infonavit," & _
                            "@Fonacot," & _
                            "@Anio," & _
                            "@Nomina," & _
                            "@Columnas," & _
                            "@FechaInicial," & _
                            "@FechaFinal," & _
                            "@FechaAplicacion)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdNomina", mintIdNomina)
        Command.Parameters.AddWithValue("Folio", mintFolio)
        Command.Parameters.AddWithValue("Infonavit", mintInfonavit)
        Command.Parameters.AddWithValue("Fonacot", mintFonacot)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("Nomina", mintNomina)
        Command.Parameters.AddWithValue("Columnas", mintColumnas)
        Command.Parameters.AddWithValue("FechaInicial", mdatFechaInicial)
        Command.Parameters.AddWithValue("FechaFinal", mdatFechaFinal)
        Command.Parameters.AddWithValue("FechaAplicacion", mdatFechaAplicacion)


        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
